package com.hptpd.questionnairesurvey.vo;

import com.google.common.collect.Lists;
import com.hptpd.questionnairesurvey.domain.Survey;
import com.hptpd.questionnairesurvey.utils.AbstractMyBeanUtils;
import com.hptpd.questionnairesurvey.utils.DateUtil;
import lombok.Data;

import java.util.Date;
import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* Date: 2019/10/23
 * \*
 * \* Description:
 * \
 *
 * @author walter_long
 */
@Data
public class SurveyVo {
    private String id;

    private String name;

    private String tag;

    private Integer respondentSum;

    private Integer doneSum;

    private Date createdAt;

    private String createTime;

    private String state;

    private QuestionnaireVo questionnaireVo;

    public static List<SurveyVo> convertSurvey(List<Survey> surveys) {
        List<SurveyVo> surveyVos = Lists.newLinkedList();
        for (Survey survey : surveys) {
            surveyVos.add(convertSurvey(survey));
        }
        return surveyVos;
    }

    public static SurveyVo convertSurvey(Survey survey) {
        if (null == survey) {
            return null;
        }
        SurveyVo surveyVo = new SurveyVo();
        AbstractMyBeanUtils.copyProperties(survey, surveyVo);
        surveyVo.setQuestionnaireVo(QuestionnaireVo.convertQuestionnaire(survey.getQuestionnaire()));
        surveyVo.setCreateTime(DateUtil.dateToString(surveyVo.getCreatedAt()));
        return surveyVo;
    }
}
